/*
TABLE CONTENTS
-------------------------------
	01. OWL Carousel
	02. Scroll totop
-------------------------------
 */
 
//Show dropdown on hover only for desktop devices
//-----------------------------------------------
var delay=0, setTimeoutConst;
if ((Modernizr.mq('only all and (min-width: 768px)') && !Modernizr.touch) || $("html.ie8").length>0) {
	$('.main-navigation .navbar-nav>li.dropdown, .main-navigation li.dropdown>ul>li.dropdown').hover(
	function(){
		var $this = $(this);
		setTimeoutConst = setTimeout(function(){
			$this.addClass('open').slideDown();
			$this.find('.dropdown-toggle').addClass('disabled');
		}, delay);

	},	function(){ 
		clearTimeout(setTimeoutConst );
		$(this).removeClass('open');
		$(this).find('.dropdown-toggle').removeClass('disabled');
	});
};

//Show dropdown on click only for mobile devices
//-----------------------------------------------
if (Modernizr.mq('only all and (max-width: 767px)') || Modernizr.touch) {
	$('.main-navigation [data-toggle=dropdown], .header-top [data-toggle=dropdown]').on('click', function(event) {
	// Avoid following the href location when clicking
	event.preventDefault(); 
	// Avoid having the menu to close when clicking
	event.stopPropagation(); 
	// close all the siblings
	$(this).parent().siblings().removeClass('open');
	// close all the submenus of siblings
	$(this).parent().siblings().find('[data-toggle=dropdown]').parent().removeClass('open');
	// opening the one you clicked on
	$(this).parent().toggleClass('open');
	});
};

/** 01. OWL Carousel
 **************************************************************** **/
if ($('.owl-carousel').length>0) {
	for(var owl_carousel_count=1;owl_carousel_count<20;owl_carousel_count++){
		$(".owl-carousel.carousel"+owl_carousel_count).owlCarousel({
			items: owl_carousel_count,
			pagination: false,
			navigation: true,
			navigationText: false
		});
		$(".owl-carousel.carousel-autoplay"+owl_carousel_count).owlCarousel({
			items: owl_carousel_count,
			autoPlay: 3000,
			pagination: false,
			navigation: true,
			navigationText: false
		});
		$(".owl-carousel.clients"+owl_carousel_count).owlCarousel({
			items: owl_carousel_count,
			autoPlay: true,
			pagination: false,
			itemsDesktopSmall: [992,5],
			itemsTablet: [768,4],
			itemsMobile: [479,3]
		});
	}
	$(".owl-carousel.content-slider").owlCarousel({
		singleItem: true,
		autoPlay: 3000,
		navigation: false,
		navigationText: false,
		pagination: false
	});
	$(".owl-carousel.content-slider-with-controls").owlCarousel({
		singleItem: true,
		autoPlay: false,
		navigation: true,
		navigationText: false,
		pagination: true
	});
	$(".owl-carousel.content-slider-with-controls-autoplay").owlCarousel({
		singleItem: true,
		autoPlay: 3000,
		navigation: true,
		navigationText: false,
		pagination: true
	});
	$(".owl-carousel.content-slider-with-controls-bottom").owlCarousel({
		singleItem: true,
		autoPlay: false,
		navigation: true,
		navigationText: false,
		pagination: true
	});
};

/** 02. Scroll totop
 **************************************************************** **/
$(window).scroll(function() {
	if($(this).scrollTop() != 0) {
		$(".scrollToTop").fadeIn();	
	} else {
		$(".scrollToTop").fadeOut();
	}
});

$(".scrollToTop").click(function() {
	$("body,html").animate({scrollTop:0},800);
});